package com.ydd.controller.amidn;

import com.ydd.dto.IndexSetTopPage;
import com.ydd.dto.ListDTO;
import com.ydd.dto.RegDTO;
import com.ydd.result.Result;
import com.ydd.service.HomePageService;
import com.ydd.vo.IYddArticleDataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/index")
public class HomePageController {

    @Autowired
    private HomePageService homePageService;


    /**
     * 热门文章置顶
     * @return
     */
    @GetMapping("/new")
    public Result setTop(IndexSetTopPage setTopPage){
        return homePageService.setTop(setTopPage);
    }

    /**
     * 文章列表数据
     * @return
     */
    @GetMapping("/list")
    public Result listArticle(ListDTO listDTO){
        return homePageService.listArticle(listDTO);
    }

    /**
     * 注册
     * @param regDTO
     * @return
     */
    @PostMapping("/reg")
    public Result regUser(@RequestBody RegDTO regDTO){
        System.out.println(regDTO.getPassword());
        return homePageService.regUser(regDTO);
    }

    /**
     * 最新文章
     * @return
     */
    @GetMapping("/hot")
    public Result hotArticle(){
        return homePageService.hotArticle();
    }

    /**
     * 推荐文章
     * @return
     */
    @GetMapping("/recommend")
    public Result recommend(){
        return homePageService.recommend();
    }


    /**
     * 文章详情数据
     * @return
     */
    @GetMapping("/show")
    public Result showArticleDetail(String id){
        return homePageService.showArticleDetail(id);
    }

    /**
     *  首页和全局数据
     * @return
     */
    @GetMapping("/index")
    public Result<IYddArticleDataVO> index(){
        return homePageService.index();
    }


}
